<template>
<div>
  <v-row>
    <v-col cols="12" md="3">
      <v-select
      v-model="item_select"
      :items="items"
      label="查询方式"
      outlined
      ></v-select>
    </v-col>
    <v-col cols="12" md="3">
      <v-text-field
      v-model="form.input_msg"
      :label="items_str[form.items_index]"
      :placeholder="'输入'+items_str[form.items_index]"
      outlined
      ></v-text-field>
    </v-col>
  </v-row>
  <v-row>
    <v-col cols="12" md="3">
      <div class="wcc-sheet">
        <v-btn color="primary" @click="query">查询</v-btn>
      </div>
    </v-col>
  </v-row>

  <v-row v-if="show">
    <v-col cols="6" md="3">
      <v-card outlined v-for="(item, i) in resmsg" :key="i">
        <v-list-item three-line>
          <v-list-item-content>
            <div class="overline mb-4">学生信息</div>
            <v-list-item-title class="headline mb-1">{{item.name}}</v-list-item-title>
            <v-list-item-subtitle>{{item.id}}</v-list-item-subtitle>
            <v-list-item-subtitle>{{item.mclass}}</v-list-item-subtitle>
          </v-list-item-content>
          <v-list-item-avatar
            tile
            size="80"
            color="blue"
          ></v-list-item-avatar>
        </v-list-item>
        <v-card-actions>
          <v-btn
            text
            color="deep-purple accent-4"
            @click="$router.push({path:'/StudentMsgShower',query:{id:item.id}})"
          >
            成绩信息
          </v-btn>
        </v-card-actions>
      </v-card>
    </v-col>
  </v-row>

  <v-dialog
      v-model="errorDialog"
      width="500"
    >
      <v-card>
        <v-card-title class="headline">没有查询到信息</v-card-title>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn
            color="primary"
            text
            @click="errorDialog = false"
          >OK</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
</div>
</template>

<script>

export default {
  name: 'QueryStudents',

  data: () => ({
    items: ['根据学号查询', '根据姓名查询'],
    items_str: ["学号", "姓名"],
    item_select: 0,
    isHide: true,
    errorDialog: false,
    form: { items_index: 0, input_msg: "" },
    show: false,
    select_id: "1706210123",
    resmsg: [{id:"", name: "", mclass:""}],
  }),

  watch: {
    item_select(v) {
      for (let i in this.items) {
        if (v == this.items[i]) {
          this.form.items_index = i
          break
        }
      }
    }
  },

  methods: {
    query() {
      this.$axios.post("/api/PostStudents.php", "ajax="+JSON.stringify(this.form))
      .then((res)=>{
        console.log(res)
        this.resmsg = [res.data]
        this.show = true
      }).catch((e)=>{
        console.log(e)
      })
    }
  },
};
</script>

<style scoped>
</style>